import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloWorld extends HttpServlet {


    public HelloWorld() {
        super();
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置响应内容类型
        this.doPost(request, response);
    }
    public void doPost(HttpServletRequest request,HttpServletResponse response)
            throws ServletException,IOException{
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("name");
        String pwd = request.getParameter("pwd");
        if((name!=null&&!name.equals(""))&&(pwd!=null&&!pwd.equals(""))){
            if(name.equals("mr")&&pwd.equals("123456")){
                request.getRequestDispatcher("success.jsp").forward(request,response);
            }
            else{
                response.sendRedirect("error.jsp");
            }
        }
    }

    @Override
    public void destroy() {
        super.destroy();
    }

}
